package tcp;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class TcpClient {

	public static void main(String[] args) throws Exception{
		Socket socket = new Socket("127.0.0.1", 4444);
		BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
		OutputStream outputStream = socket.getOutputStream();
		String line;
		
//		Scanner scanner = new Scanner(System.in);
		String string="";
		
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
		while (true) {
			line = reader.readLine();
			System.out.println(line);
			string = bufferedReader.readLine();
			outputStream.write((string+"\n").getBytes());
			line = reader.readLine();
			System.out.println(line);
			if(string.equals("bye"))
				break;
			while (!(line=reader.readLine()).equals("finish!")) {
				System.out.println(line);
				
			}
//			line=reader.readLine();
//			System.out.println(line);

		}
		socket.close();
		reader.close();
		outputStream.close();
	}

}
